

project , uses("candidate_elections.dta")


*Appendix: Missing data table
	use "candidate_elections.dta", clear //open data
	gen missing_data = spending_total==. 
	drop if year==1918
	gen p = .
	replace p = 1 if  year<1918
	replace p= 2 if year>1918 & year<1945
	replace p= 3 if year>=1945 & year<1970
	replace p= 4 if year>=1970 & year<1990
	replace p = 5 if year>=1990
	contract missing_data p
	
	
	reshape wide _freq , i(p) j(missing_data)
	egen x = total(_freq1)
	egen y = total(_freq0)
	gen z = x+y
	local x=x[1]
	local y = y[1]
	local z = 100*y[1] / (x[1] +y[1])
	di "`z'"
	
	forval i=1/5 {
		local `i'_notreported =_freq1[`i']
		local `i'_total =_freq0[`i'] + _freq1[`i']
		local pct`i' = 100*_freq0[`i'] / (_freq0[`i'] + _freq1[`i'])
		}
	
	 	
	
	quietly {
		cap log close
		set linesize 255
		log using ./tables/missing_data.tex, text replace
		noisily dis "\begin{table}[t]"
		noisily dis "\begin{center}"
		noisily dis "\caption{ {\bf Missing Spending Returns \label{tab:missing}} }"
		noisily dis "\begin{tabular}{l ccc}"
		noisily dis "\toprule \toprule"
		noisily dis "   & \# Missing  & Total \#  & Pct. \\"
		noisily dis " Period & Candidate Reports & Candidates &  Reporting \\"
		noisily dis "\midrule"
	
		noisily dis " 1885-1917 & " %9.0fc `1_notreported' " & " %9.0fc `1_total' " & " %9.2fc `pct1'  "\\"
		noisily dis " 1919-1944 & " %9.0fc `2_notreported' " & " %9.0fc `2_total' " & " %9.2fc `pct2'  "\\"
		noisily dis " 1945-1969 & " %9.0fc `3_notreported' " & " %9.0fc `3_total' " & " %9.2fc `pct3'  "\\"
		noisily dis " 1970-1996 & " %9.0fc `4_notreported' " & " %9.0fc `4_total' " & " %9.2fc `pct4'  "\\"
		noisily dis " 1997-2019 & " %9.0fc `5_notreported' " & " %9.0fc `5_total' " & " %9.2fc `pct5'  "\\"
		noisily dis "\midrule"
		noisily dis " Total & " %4.0f `x' " & " %4.0f `y' " & " %4.2f `z'  "\\"
	
		noisily dis "\bottomrule \bottomrule"
		noisily dis "\end{tabular}"
		noisily dis "\end{center}"	
		noisily dis " \footnotesize{ \textsc{Note:} Due to the loss of all the filed spending reports, the election of 1918 is "
		noisily dis " excluded from the calculations.} "
		noisily dis "\end{table}"
		
		log off
	}	
			
	project , creates("tables/missing_data.tex")	

	
